package Pattern.FactoryPattern.workTest.Work.Program5;

abstract class ImageReaderFactory{
    abstract ImageReader init();
}

class GifReaderFactory extends ImageReaderFactory{

    @Override
    public ImageReader init() {
        System.out.println("已创建Gif图片读取器");
        return new GifReader();
    }
}

class JpgReaderFactory extends ImageReaderFactory{

    @Override
    public ImageReader init() {
        System.out.println("已创建Jpg图片读取器");
        return new JpgReader();
    }
}

abstract class ImageReader{
    public abstract void Reader();
}

class GifReader extends ImageReader{

    @Override
    public void Reader() {
        System.out.println("已读取Gif图片");
    }
}

class JpgReader extends ImageReader{

    @Override
    public void Reader() {
        System.out.println("已读取Jpg图片");
    }
}

public class Test {
    public static void main(String[] args) {
        ImageReader imageReader;
        ImageReaderFactory imageReaderFactory;
        imageReaderFactory = new GifReaderFactory();
        imageReader = imageReaderFactory.init();
        imageReader.Reader();
        System.out.println();
        imageReaderFactory = new JpgReaderFactory();
        imageReader = imageReaderFactory.init();
        imageReader.Reader();
    }
}
